package com.huawei.bitfun.insight.utils;

import org.apache.commons.io.FilenameUtils;

public enum TraceFileType {
    DB_EXTENSION("db"),
    HTRACE_EXTENSION("htrace"),
    FTRACE_EXTENSION("ftrace"),
    INSIGHT_EXTENSION("insight"),
    DEFAULT_EXTENSION("default");
    private String extension;

    TraceFileType(String extension) {
        this.extension = extension;
    }

    public static TraceFileType getTraceFileType(String fileName) {
        return switch (FilenameUtils.getExtension(fileName)) {
            case "db" -> TraceFileType.DB_EXTENSION;
            case "htrace" -> TraceFileType.HTRACE_EXTENSION;
            case "ftrace" -> TraceFileType.FTRACE_EXTENSION;
            case "insight" -> TraceFileType.INSIGHT_EXTENSION;
            default -> TraceFileType.DEFAULT_EXTENSION;
        };
    }

    @Override
    public String toString() {
        return extension;
    }
}
